<h3>Sent feedbacks</h3>


<hr/>
<?php
$limit = 4;

if (isset($_GET['pg']))
    $cpg = $_GET['pg'];
else
    $cpg = 1;


require_once 'classes/ask.class.php';
require_once 'classes/work.class.php';


$sql = "SELECT `f`.`comment` AS `comment`,`a`.`workid`,`a`.`id`, COUNT(*) AS `sF`, SUM(`a`.`finished`) AS `sumfinished`,`w`.`uid` AS `foruser`,`w`.`catid` FROM `feedbacks` AS `f`,`asks` AS `A`, `works` AS `w` WHERE `f`.`workid`=`w`.`id` AND `a`.`foruid`='" . $_SESSION['uid'] . "' AND `w`.`id`=`a`.`workid`  GROUP BY `w`.`id` ORDER BY `id` ASC";
$query = $db->query($sql) or die(mysql_error());
$allpages = mysql_num_rows($query);
// END

echo "<ol class=\"timeline\" id=\"updates\" style='list-style-type:none;margin:0'>";
$pg = 0;
$from = ($cpg - 1) * $limit;


//$db->select("`works`", "*", "`uid`='" . $_SESSION['uid'] . "'");
$isviso = mysql_num_rows($query);

$pages = $isviso / $limit;
if ($pages > (integer) $pages)
    $pages = $pages + 1;

//echo (integer)$pages;

while ($asks = $db->fetch($query)) {
    
    $aid = $asks->id;
    $last_ask = $aid;
    $ask = new Ask($aid);
    $wid = $ask->getWorkId();
    $f4 = $asks->foruser;
    $fuser = new User($f4);
    $f4 = $fuser->getName()." ".$fuser->getSurname();
    $work = new Work($wid);
    require_once 'classes/category.class.php';
    $cat = new Category($work->getCategoryId());
        $datep = date("Y-m-d", strtotime(date("Y-m-d", strtotime(date("Y-m-d", strtotime($work->getDate())))) . " +2 week"));
        $datec = date("Y-m-d");
        echo "<li style='border-style:solid;border-width:1px;border-color:#DDD;padding:10px;margin:5px;background-color:#f7f7f7;display:inline-table;width: 250px;max-width: 250px;height:210px;'>";
        echo "<p style='margin:0;font-size:11px;'>" . $work->getDate() . "</p>";
        echo "<p style='margin:0;font-size:11px;'><strong>" . $cat->getName() . "</strong></p>";
        echo "<div style='min-height:30px;max-height:70px;height:45px;border:0;padding:0;margin:0;'><p style='line-height:15px;font-size:11px;display:block;'><i>" . substr($work->getDescription(), -100) . "...</i></p></div>";
        echo "<p style='margin:0;font-size:11px;'>Feedback for: <strong>$f4</strong></p>";
        $sql2 = "SELECT DISTINCT `feedbacks`.`id`, `feedbacks`.`workid`,`comment`,`feedbacks`.`uid`, AVG(`speed`) AS `speed`, AVG(`quality`) AS `quality` FROM `feedbacks` INNER JOIN `works` ON `works`.`id`=`feedbacks`.`workid` WHERE `works`.`id` = '$wid'";
        $query2 = $db->query($sql2);
        $res = $db->fetch($query2);
        $s = round($res->speed);
        $q = round($res->quality);
        ?>
        <table cellpadding="0" cellspacing="0" style="width:220px;">
            <tr style="height:30px">
                <td style="padding:5px 3px 3px 6px;margin:0;width: 100px">Speed/On Time</td>
                <td style="padding:5px 3px 3px 6px;;margin:0">
                    <?php
                    for ($c = 0; $c < $s; $c++)
                        echo "<img style='width:16px;' src='star_48.png'/>";
                    $c = 0;
                    $s = 0;
                    ?>
                </td>
            </tr>
            <tr style="height:30px">
                <td style="padding:5px 3px 3px 6px;margin:0">
                    Quality 
                </td>
                <td style="padding:5px 3px 3px 6px;;margin:0">
                    <?php
                    for ($c = 0; $c < $q; $c++)
                        echo "<img style='width:16px;' src='star_48.png'/>";
                    $c = 0;
                    $q = 0;
                    ?>
                </td>
            </tr>
        </table>
        <?php
        echo "<p>".$asks->comment."</p>";
        echo "</li>";
   
}
echo "</ol>";
?>
